<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>websocket</title>
</head>
<body>
  
</body>
<script>
  let ws = "ws://localhost:9501";
  var websocket = new WebSocket(ws);
  websocket.onopen = function(event) {
    console.log("连接成功");
  }
  websocket.onclose = function(event) {
    console.log("关闭");
  }
  websocket.onmessage = function(event) {
    console.log(event.data);
  }
  websocket.onerror = function(event, error) {
    console.log(error);
  }
</script>
</html>